package com.trg.flex
{
	import flash.utils.Dictionary;
	
	/**
	 * This serves as a base for simple locators like <code>Delegates.as</code> and <code>Services.as</code>.
	 * It stores a repository of instantiated objects, one per class that is requested.
	 * And automatically adds to that store when a new class is requested.
	 */
	public class StaticLocatorBase
	{
		private static var map : Dictionary = new Dictionary();
		
		/**
		 * Returns an instance of the given class. If that class has not been requested
		 * before, it creates a new instance and stores it. If it has been requested before,
		 * it pulls it from its store and returns it.
		 */
		protected static function getSingleton(klass : Class) : * {
			var o : * = map[klass];
			if (o == null) {
				o = new klass();
				map[klass] = o;
			}
			return o;
		}
		
		protected static function getPrototype(klass : Class) : * {
			return new klass();
		}

	}
}